/**
 * 
 */
package com.p2p.front.dal.dao;

import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.front.dal.model.TenderAutoSetting;

/**
 * @author ruiqi
 *
 */
public interface TenderAutoSettingDao extends BaseMapper {

	// insert into table (ID,USER_ID,STATUS,TOTAL_AMOUNT,ONCE_AMOUNT,MIN_RATE,MAX_RATE,MIN_DEADLINE,MAX_DEADLINE,REPAY_METHOD,MIN_CREDIT_LEVEL,MAX_CREDIT_LEVEL,LIMIT_AMOUNT)values(#{id},#{userId},#{status},#{totalAmount.cent},#{onceAmount.cent},#{minRate},#{maxRate},#{minDeadline},#{maxDeadline},#{repayMethod},#{minCreditLevel},#{maxCreditLevel},#{limitAmount.cent})
	// update table set ID=#{id},USER_ID=#{userId},STATUS=#{status},TOTAL_AMOUNT=#{totalAmount.cent},ONCE_AMOUNT=#{onceAmount.cent},MIN_RATE=#{minRate},MAX_RATE=#{maxRate},MIN_DEADLINE=#{minDeadline},MAX_DEADLINE=#{maxDeadline},REPAY_METHOD=#{repayMethod},MIN_CREDIT_LEVEL=#{minCreditLevel},MAX_CREDIT_LEVEL=#{maxCreditLevel},LIMIT_AMOUNT=#{limitAmount.cent}  where id=#{id}

	String columns = "ID,USER_ID,STATUS,TOTAL_AMOUNT,ONCE_AMOUNT,MIN_RATE,MAX_RATE,MIN_DEADLINE,MAX_DEADLINE,REPAY_METHOD,MIN_CREDIT_LEVEL,MAX_CREDIT_LEVEL,LIMIT_AMOUNT";
	
	@Update("replace p2p_tender_auto_setting (USER_ID,STATUS,TOTAL_AMOUNT,ONCE_AMOUNT,MIN_RATE,MAX_RATE,MIN_DEADLINE,MAX_DEADLINE,REPAY_METHOD,MIN_CREDIT_LEVEL,MAX_CREDIT_LEVEL,LIMIT_AMOUNT)values(#{userId},0,#{totalAmount.cent},#{onceAmount.cent},#{minRate},#{maxRate},#{minDeadline},#{maxDeadline},#{repayMethod},#{minCreditLevel},#{maxCreditLevel},#{limitAmount.cent})")
	public int replace(TenderAutoSetting tenderAutoSetting);
	
	@Update("insert into p2p_tender_auto_setting (USER_ID,STATUS,TOTAL_AMOUNT,ONCE_AMOUNT,MIN_RATE,MAX_RATE,MIN_DEADLINE,MAX_DEADLINE,REPAY_METHOD,MIN_CREDIT_LEVEL,MAX_CREDIT_LEVEL,LIMIT_AMOUNT)values(#{userId},#{status},#{totalAmount.cent},#{onceAmount.cent},#{minRate},#{maxRate},#{minDeadline},#{maxDeadline},#{repayMethod},#{minCreditLevel},#{maxCreditLevel},#{limitAmount.cent})")
	public int insert(TenderAutoSetting tenderAutoSetting);
	
	@Update("update p2p_tender_auto_setting set TOTAL_AMOUNT=#{totalAmount.cent},ONCE_AMOUNT=#{onceAmount.cent},MIN_RATE=#{minRate},MAX_RATE=#{maxRate},MIN_DEADLINE=#{minDeadline},MAX_DEADLINE=#{maxDeadline},REPAY_METHOD=#{repayMethod},MIN_CREDIT_LEVEL=#{minCreditLevel},MAX_CREDIT_LEVEL=#{maxCreditLevel},LIMIT_AMOUNT=#{limitAmount.cent} where ID=#{id} AND USER_ID=#{userId}")
	public int update(TenderAutoSetting tenderAutoSetting);
	
	@Update("update p2p_tender_auto_setting set STATUS=#{status} where USER_ID=#{userId}")
	public int updateStatus(TenderAutoSetting tenderAutoSetting);
	
	@Select("select "+columns+ " from p2p_tender_auto_setting where USER_ID=#{userId}")
	@ResultMap("TenderAutoSettingResultMap")
	public TenderAutoSetting getByUserId(String userId);


}
